import { emit } from "./utils/scoket.js";
export const getPosition = (ele) => {
    const po = ele.style.transform;
    const xy = po.slice(po.indexOf("(") + 1, po.indexOf(")")).split(",");
    return {
        x: +xy[0].replace("px", ""),
        y: +xy[1].replace("px", ""),
    };
};
//按键触发移动
let keyword = ["a", "s", "d", "w", "j"];
let lastKey = "";
export function transfrom(e) {
    if (!keyword.includes(e.key))
        return;
    if (lastKey === e.key)
        return;
    lastKey = e.key;
    if (localStorage.role === "p1") {
        emit.p1("/key/down", { key: e.key });
    }
    else if (localStorage.role === "p2") {
        emit.p2("/key/down", { key: e.key });
    }
}
//停止移动
export function stopTransform(e) {
    if (!keyword.includes(e.key))
        return;
    lastKey = "";
    if (localStorage.role === "p1") {
        emit.p1("/key/up", { key: e.key });
    }
    else if (localStorage.role === "p2") {
        emit.p2("/key/up", { key: e.key });
    }
}
